// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/order/api/WorkOrderApi'

import SubmitClass from '@api/order/model/AddWorkOrderEventReq'
import EventClass from '@api/order/model/WorkOrderEventDto'

const CLIENT = CORE.grpcCLIENT(Client)

const EVENT = [EventClass, 'workOrderEventDto']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 撤销 —————————————————————————————— //

  async cancel(one, TIP = '工单撤销') {
    const DTO = CORE.grpcDTO(SubmitClass, one, EVENT)
    await CORE.grpc(TIP, CLIENT, 'cancelTask', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 指派 —————————————————————————————— //

  async assign(one, TIP = '工单指派') {
    const DTO = CORE.grpcDTO(SubmitClass, one, EVENT)
    await CORE.grpc(TIP, CLIENT, 'assignTask', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 转派 —————————————————————————————— //

  async forward(one, TIP = '工单转派') {
    const DTO = CORE.grpcDTO(SubmitClass, one, EVENT)
    await CORE.grpc(TIP, CLIENT, 'forwardTask', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 挂起 —————————————————————————————— //

  async suspend(one, TIP = '工单挂起') {
    const DTO = CORE.grpcDTO(SubmitClass, one, EVENT)
    await CORE.grpc(TIP, CLIENT, 'suspendTask', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 审核 —————————————————————————————— //

  async review(one, TIP = '工单审核') {
    const DTO = CORE.grpcDTO(SubmitClass, one, EVENT)
    await CORE.grpc(TIP, CLIENT, 'reviewTask', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 挂起审批 —————————————————————————————— //

  async suspendReview(one, TIP = '工单挂起审批') {
    const DTO = CORE.grpcDTO(SubmitClass, one, EVENT)
    await CORE.grpc(TIP, CLIENT, 'suspendReviewTask', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 加急 —————————————————————————————— //

  async hasten(one, TIP = '工单加急') {
    const DTO = CORE.grpcDTO(SubmitClass, one, EVENT)
    await CORE.grpc(TIP, CLIENT, 'hastenTask', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 追记 —————————————————————————————— //

  async note(one, TIP = '工单追记') {
    const DTO = CORE.grpcDTO(SubmitClass, one, EVENT)
    await CORE.grpc(TIP, CLIENT, 'addNoteTask', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 评价 —————————————————————————————— //

  async evaluate(one, TIP = '工单评价') {
    const DTO = CORE.grpcDTO(SubmitClass, one, EVENT)
    await CORE.grpc(TIP, CLIENT, 'evaluateTask', DTO)
    return CORE.grpcOK(TIP)
  },
}
